import {
  request
} from '../../request/index'
import regeneratorRuntime from '../../lib/runtime/runtime'
Page({

  data: {
    tabs: [{
      id: 0,
      value: "关注",
      isActive: true
    },
    {
      id: 1,
      value: "粉丝",
      isActive: false
    },
  ],
  attentions:[],
  fans:[],

  },

  onLoad: function (options) {
    let {uid} = options
    if (options.uid) {
      this.getAttentions(uid)
      this.getFans(uid)
    }
  },

    //点击切换tab
    handleTabsItemChange(e) {
      const {
        index
      } = e.detail
  
      let {
        tabs
      } = this.data
  
      tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false)
  
      this.setData({
        tabs
      })
    },

    //获取用户关注
    async getAttentions(id){
      let res = await request({url:"/user/follows",data:{uid:id}})
      this.setData({
        attentions:res.data.follow
      })
    },

    //获取用户粉丝
    async getFans(id){
      let res = await request({url:"/user/followeds",data:{uid:id}})
      this.setData({
        fans:res.data.followeds
      })
    },

    //关注功能
    async handleMutual(e){
      let t = e.currentTarget.dataset.t
      let id = e.currentTarget.id
      let res = await request({url:"/follow",data:{id:id,t:t}})
      if(t==="1"){
        wx.showToast({
          title: '关注成功',
          icon: 'none',
        });
      }else{
        wx.showToast({
          title: '取消关注',
          icon: 'none',
        });
      }
      
    }
})